<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        // ES6允许按照一定的模式，从数组和对象中提取，对变量进行赋值，这被称为解构
        // 解构赋值:根据结构解析数据，并进行赋值操作

        // 1.基本用法(完全结构)
        let arr=["花花","红红","嘻嘻"];
        let [a,b,c]=arr;
        console.log(a,b,c);
        // 2.不完全解构
        let [,,dd,ee]=["韩非子","无锡","南京","日本"];
        console.log(dd,ee);
        // 3.剩余解构,格式:...变量名
            // 剩余解构只对没有被取值的剩余的数据进行数组包装
            // 剩余解构的语法必须出现在解构模式的最后一位
        let [aaa,...bbb]=["aa","bb","cc","dd","ee"];
        console.log(aaa);
        console.log(bbb);

        // 4.模式匹配失败
        let [f]=[];
        console.log(f);

        // 5.多维数组的嵌套解构
        let [,temp1,,[,temp2]]=["alice","lucy","lili",["admin","admin2","admin3"]];
        console.log(temp1,temp2);
        
        let x=10;
        let y=20;
        [x,y]=[y,x];
        console.log(x,y);
    </script>
</head>
<body>
    
</body>
</html>